package com.nk.iexam.adapter;

import java.util.List;

import com.nk.iexam.R;
import com.nk.iexam.models.TheoryReview;

import android.app.Activity;
import android.content.Context;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class ReviewAdapter extends ArrayAdapter<TheoryReview>
{
	private Context _context;
	private int _layoutResourceId;  
	private List<TheoryReview> _data = null;

	public ReviewAdapter(Context context_, int layoutResourceId_, List<TheoryReview> data_) 
	{
		super(context_, layoutResourceId_, data_);
		this._layoutResourceId = layoutResourceId_;
		this._context = context_;
		this._data = data_;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View row = convertView;
		CategoryHolder holder = null;

		if(row == null)
		{
			LayoutInflater inflater = ((Activity)_context).getLayoutInflater();
			row = inflater.inflate(_layoutResourceId, parent, false);

			holder = new CategoryHolder();
			holder.txtQuestion = (TextView)row.findViewById(R.id.questionTextView);
			holder.txtAnswer = (TextView)row.findViewById(R.id.answerTextView);

			row.setTag(holder);
		}
		else
		{
			holder = (CategoryHolder)row.getTag();
		}

		TheoryReview data = _data.get(position);
		holder.txtQuestion.setText(Html.fromHtml(data.getQuestion()));
		holder.txtAnswer.setText(Html.fromHtml(data.getAnswer()));
		
		return row;
	}

	static class CategoryHolder
	{
		TextView txtQuestion;
		TextView txtAnswer;
	}
}
